﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using ZBJF.Warranty.Common.Common;
using ZBJF.Warranty.Model;
using ZBJF.Warranty.Model.ViewModel.SocketModel;
namespace ZBJF.Warranty.BLL
{
    public partial class WeiXinChatRecordService
    {
        /// <summary>
        /// 分页获取通话记录
        /// </summary>
        /// <param name="model"></param>
        /// <param name="total"></param>
        /// <returns></returns>
        public IQueryable<WeiXinChatRecord> GetPagingList(WeiXinChatRecordParam model, out int total)
        {
            var whereExpression = PredicateExtensions.True<WeiXinChatRecord>();
            //OpenId
            if (!string.IsNullOrWhiteSpace(model.OpenId))
            {
                whereExpression = whereExpression.And(o => o.OpenId == model.OpenId);
            }
            //时间范围
            if (model.TimeRange > 0)
            {
                DateTime start = DateTime.Now;
                DateTime end = DateTime.Now;
                if (model.TimeRange == 100)
                {
                    start = start.AddMonths(-1); 
                }
                else if (model.TimeRange == 200)
                {
                    start = start.AddMonths(-2);
                }
                else if (model.TimeRange == 300)
                {
                    start = start.AddMonths(-3);
                }
                whereExpression = whereExpression.And(o => o.CreateTime>start && o.CreateTime < end);
            }
            //消息类型
            if ((int)model.MessageType > 0)
            {
                whereExpression = whereExpression.And(o => o.MessageType == (int)model.MessageType);
            }
            //消息
            if (!string.IsNullOrWhiteSpace(model.Message))
            {
                whereExpression = whereExpression.And(o => o.Message.Contains(model.Message));
            }

            return LoadPagerEntities<WeiXinUserInfo>(model.PageIndex, model.iDisplayLength, out total,
                whereExpression, model.iSorts);
        }
    }
}
